# public static Long ELFHash(String str) {
#         long hash = 0;
#         long x=0;
#         for(int i=0;i<str.length();i++)
#         {
#             hash = (hash<<4)+str.charAt(i);
#             if((x=hash & 0xF0000000L) != 0)
#             {
#                 hash^=(x>>24);
#             }
#             hash &=~x;
#         }
#         return hash;
#     }
def elfhash(str):
    hash = 0
    x=0
    for i in str:
        hash = (hash<<4)+i
        x=hash & 0xF0000000L
        if x != 0:
            hash^=(x>>24)
        hash &=~x
    
    return hash

if __name__ == '__main__':
    println(elfhash("fafas"))